﻿
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <title>叩丁狼CRM(演示版)</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <#include "../common/head.ftl"/>
    <link rel="stylesheet" href="/css/core.css"/>
</head>
<body>
<#assign menu="employee"/>
<div class="container " style="margin-top: 20px">
    <#include "../common/welcome.ftl"/>
    <div class="row">
        <#include "../common/menu.ftl"/>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">员工管理</h1>
                </div>
            </div>

            <form class="form-inline" id="searchForm" action="/employee/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="请输入姓名/邮箱">
                </div>
                <div class="form-group">
                    <label for="dept">部门:</label>
                    <select class="form-control" id="dept" name="deptId">
                        <option value="-1">全部</option>
                        <#list departmentList as d>
                            <option value="${d.id}">${d.name}</option>
                        </#list>
                    </select>
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a href="/employee/input.do" class="btn btn-success">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
                <a role="button" data-url="/employee/batchDelete.do" class="btn btn-danger" id="batch">
                    <span class="glyphicon glyphicon-trash"></span>批量删除
                </a>
                <a href="/employee/export.do" target="_blank" class="btn btn-info">
                    <span class="glyphicon glyphicon-export"></span>导出
                </a>
                <a role="button"  class="btn btn-warning import">
                    <span class="glyphicon glyphicon-import"></span>导入
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th><input type="checkbox" class="both">全选</th>
                    <th>编号</th>
                    <th>名称</th>
                    <th>邮箱</th>
                    <th>年龄</th>
                    <th>部门</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity>
                     <tr>
                         <td><input type="checkbox" class="single" name="ids" value="${(entity.id)!}"></td>
                        <td>${entity_index + 1}</td>
                        <td>${entity.name}</td>
                        <td>${entity.email}</td>
                        <td>${entity.age}</td>
                        <td>${entity.department.name}</td>
                         <td>

                             <a href="/employee/input.do?id=${entity.id}" class="btn btn-info btn-xs input_btn">
                                 <span  class="glyphicon glyphicon-pencil"></span> 编辑
                             </a>

                             <@shiro.hasPermission name="employee:delete">
                             <a role="button" data-url="/employee/delete.do?id=${entity.id}" class="btn btn-danger btn-xs delete_btn" >
                                 <span class="glyphicon glyphicon-trash"></span> 删除
                             </a>
                             </@shiro.hasPermission>
                         </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<!-- 导入员工 -->
<div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">导入员工</h4>
            </div>
            <div class="modal-body">
                <!--填充编辑界面-->
                <form id="editForm" class="form-horizontal" action="/employee/importExcel.do"
                      enctype="multipart/form-data" method="post">
                    <input type="hidden" name="id"/>
                    <div class="form-group" >
                        <label for="name" class="col-lg-4 control-label">上传文件：</label>
                        <div class="col-lg-6">
                            <input type="file" name="xls" accept="application/vnd.ms-excel" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-lg-4 control-label">参考模板：</label>
                        <div class="col-lg-6">
                            <a href="/template/employee.xls" class="btn btn-success btn-block">
                                <span class="glyphicon glyphicon-download"></span> 下载模板
                            </a>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary importBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {

        //部门回显
        $("#dept").val(${qo.deptId});


        <#--提交查询-->
        $("#btn_query").click(function () {
            $("#searchForm").submit();
        });


        $(".single").click(function () {
            if($(".single").size() == $(".single:checked").size()){
                $(".both").prop("checked",true);
            }else{
                $(".both").prop("checked",false);
            }

        });

        $(".both").click(function () {
            $(".single").prop("checked",this.checked);
        });


        //批量删除
        $("#batch").click(function () {
            if (!$(".single:checked").size()) {
                $.messager.alert("温馨提示","至少选择一位员工");
            }else{
                var ids = $.map($(".single:checked"),function (ele) {
                    return ele.value;
                });
                var url = ($(this).data("url"));
                $.get(url,{"ids":ids},function(data){
                    if(data.succeed){
                        doSucceed();
                    }else{
                        $.alert("温馨提示","请稍后再试");
                    }
                });
            };

        });

        //员工导入
        $(".import").click(function () {
            $("#importModal").modal("show");

        });

        //excel上传
        $(".importBtn").click(function () {
            $("#editForm").submit();
        });
    });
    $.ajaxSettings.traditional = true;
</script>
<#include "../common/mycode.ftl"/>
</body>
</html>